﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class PG7:Group
    {
        public PG7()
        {

            

            DryGasChem.Add(new ChemDryGas("SO2", .1509, 1000, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("NOX", .1656, 1, 8, 5, 3.5));
            DryGasChem.Add(new ChemDryGas("HNO3", .1628, 1, 18, 0, .00000008));
            DryGasChem.Add(new ChemDryGas("NO", .1345, 1, 2, 25, 18));
            DryGasChem.Add(new ChemDryGas("NO2", .1656, 1, 8, 5, 3.5));
            DryGasChem.Add(new ChemDryGas("ODOR", .1509, 1, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("TOLUENE", .1509, 1, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("XYLENE", .1509, 1, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("B-PINENE", .1509, 1, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("A-PINENE", .1509, 1, 8, 0, .04));
            DryGasChem.Add(new ChemDryGas("SO4", 0, 0, 0, 0, 0));
            DryGasChem.Add(new ChemDryGas("NO3", 0, 0, 0, 0, 0));
            DryGasChem.Add(new ChemDryGas("PM10", 0, 0, 0, 0, 0));
            DryGasChem.Add(new ChemDryGas("SOA", 0, 0, 0, 0, 0));
            DryGasChem.Add(new ChemDryGas("H2O", 0, 0, 0, 0, 0));
            DryGasChem.Add(new ChemDryGas("TXS", 0, 0, 0, 0, 0));
            DryGasChem[0].CalculateSpecies = true;

        }


        /// <summary>
        /// 污染物信息，包括污染物扩散率、反应速率、Henry's law 系数
        /// </summary>
        List<ChemDryGas> m_DryGasChem = new List<ChemDryGas>();
        /// <summary>
        /// 污染物信息，包括污染物扩散率、反应速率、Henry's law 系数
        /// </summary>
        public List<ChemDryGas> DryGasChem
        {
            get { return m_DryGasChem; }
            set { m_DryGasChem = value; }
        }

        public override string WriteToGroup()
        {
            string Subgroup = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 7 -- Chemical parameters for dry deposition of gases" + "\r\n";
            Subgroup += TempStr;
            TempStr = StrWriter.GetCLine();
            Subgroup += TempStr;

            //进行排序
            List<string> arry = Sort.GetPollutantRightOrder();
            List<ChemDryGas> arryChemDryGas = new List<ChemDryGas>();
            arryChemDryGas.Clear();
            foreach (string a in arry)
            {
                for (int i = 0; i < DryGasChem.Count; i++)
                {
                    if (a == DryGasChem[i].SRCNAM)
                    {
                        arryChemDryGas.Add(DryGasChem[i]);
                    }
                }
            }

            if (arryChemDryGas.Count > 0)
            {
                for (int i = 0; i < arryChemDryGas.Count; i++)
                {
                    if (arryChemDryGas[i].CalculateSpecies)
                    {
                        if (arryChemDryGas[i].IsDryGas)
                        {
                            TempStr = "!       " + arryChemDryGas[i].SRCNAM + "   =   " + arryChemDryGas[i].DIFFUSIVITY.ToString() + ",   " + arryChemDryGas[i].AlphaStar.ToString() + ",   " + arryChemDryGas[i].REACTIVITY.ToString() + ",   " + arryChemDryGas[i].MESOPHYLL_RESISTANCE.ToString() + ",   " + arryChemDryGas[i].HENRY_LAW_COEFFICIENT.ToString() + "   !" + "\r\n";
                            Subgroup += TempStr;
                        }
                    }
                }
            }
            Subgroup += "! END !" + "\r\n";
            return Subgroup;
        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {

                ChemDryGas cd = new ChemDryGas("XX", 1, 1, 1, 1, 1);

                this.DryGasChem.Add(cd.ReadFromGroup(m_dic.Key, m_dic.Value));


            }

        }

    }



    /// <summary>
    /// 污染物干沉积信息，阻力沉积模型计算气体干沉积速率的5个参数
    /// </summary>
    [Serializable]
    public class ChemDryGas : ICloneable
    {
        public ChemDryGas(string Name, double mDIFFUSIVITY, double mAlphaStar, double mREACTIVITY, double mMESOPHYLL, double mCOEFFICIENT)
        {
            this.SRCNAM = Name;
            this.DIFFUSIVITY = mDIFFUSIVITY;
            this.AlphaStar = mAlphaStar;
            this.REACTIVITY = mREACTIVITY;
            this.MESOPHYLL_RESISTANCE = mMESOPHYLL;
            this.HENRY_LAW_COEFFICIENT = mCOEFFICIENT;
        }

        //
        // 下表包含了利用阻力沉积模型计算气体干沉积速率的5个参数：

        //	Pollutant diffusivity (cm2/s) 污染物扩散率
        //	Aqueous phase dissociation constant, α*   ALPHA STAR
        //	Pollutant reactivity  污染物反应速度 
        //	Mesophyll resistance, rm (s/cm) 叶面积阻力 
        //	Henry's Law coefficient, H (dimensionless) 亨利常数
        //每种预测的污染物（在group 3中标示为1的污染物）必须列出这5个参数来计算气体干沉积

        /// <summary>
        /// 污染物名称
        /// </summary>
        string m_SRCNAM = "";
        /// <summary>
        /// 污染物名称
        /// </summary>
        public string SRCNAM
        {
            get { return m_SRCNAM; }
            set { m_SRCNAM = value; }
        }
        /// <summary>
        /// Pollutant diffusivity (cm2/s) 污染物扩散率
        /// </summary>
        double m_DIFFUSIVITY = 0;
        /// <summary>
        /// Pollutant diffusivity (cm2/s) 污染物扩散率
        /// </summary>
        public double DIFFUSIVITY
        {
            get { return m_DIFFUSIVITY; }
            set { m_DIFFUSIVITY = value; }
        }
        /// <summary>
        /// Aqueous phase dissociation constant, α*   ALPHA STAR
        /// </summary>
        double m_AlphaStar = 0;
        /// <summary>
        /// Aqueous phase dissociation constant, α*   ALPHA STAR
        /// </summary>
        public double AlphaStar
        {
            get { return m_AlphaStar; }
            set { m_AlphaStar = value; }
        }
        /// <summary>
        /// Pollutant reactivity  污染物反应速度 
        /// </summary>
        double m_REACTIVITY = 0;
        /// <summary>
        /// Pollutant reactivity  污染物反应速度 
        /// </summary>
        public double REACTIVITY
        {
            get { return m_REACTIVITY; }
            set { m_REACTIVITY = value; }
        }
        /// <summary>
        /// Mesophyll resistance, rm (s/cm) 叶面积阻力
        /// </summary>
        double m_MESOPHYLL_RESISTANCE = 0;
        /// <summary>
        /// Mesophyll resistance, rm (s/cm) 叶面积阻力
        /// </summary>
        public double MESOPHYLL_RESISTANCE
        {
            get { return m_MESOPHYLL_RESISTANCE; }
            set { m_MESOPHYLL_RESISTANCE = value; }
        }
        /// <summary>
        /// Henry's Law coefficient, H (dimensionless) 亨利常数
        /// </summary>
        double m_HENRY_LAW_COEFFICIENT = 0;
        /// <summary>
        /// Henry's Law coefficient, H (dimensionless) 亨利常数
        /// </summary>
        public double HENRY_LAW_COEFFICIENT
        {
            get { return m_HENRY_LAW_COEFFICIENT; }
            set { m_HENRY_LAW_COEFFICIENT = value; }
        }
        private bool m_CalculateSpecies = false;
        /// <summary>
        /// 是否估算污染物
        /// </summary>
        public bool CalculateSpecies
        {
            get { return m_CalculateSpecies; }
            set { m_CalculateSpecies = value; }
        }

        private bool m_IsDryGas = false;

        /// <summary>
        /// 是否是气体干沉积，默认为否
        /// </summary>
        public bool IsDryGas
        {
            get { return m_IsDryGas; }
            set { m_IsDryGas = value; }
        }

        public ChemDryGas ReadFromGroup(string name, string str)
        {
            ChemDryGas ps = new ChemDryGas("XX", 1, 1, 1, 1, 1);

            ps.SRCNAM = name;
            ps.DIFFUSIVITY = Convert.ToDouble(StrWriter.GetString(str, 1));
            ps.AlphaStar = Convert.ToDouble(StrWriter.GetString(str, 2));
            ps.REACTIVITY = Convert.ToDouble(StrWriter.GetString(str, 3));
            ps.MESOPHYLL_RESISTANCE = Convert.ToDouble(StrWriter.GetString(str, 4));
            ps.HENRY_LAW_COEFFICIENT = Convert.ToDouble(StrWriter.GetString(str, 5));

            return ps;
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }

    }




}
